
** estimate regressions for Table 3 (average effects results)
	
	***Inputs: 
	* $Data/GameUserWPdaily_norm.dta
	* $Data/maxmindirectionsmonth_zip260.dta
	
	***Outputs: 
	* $Results/tablepanela.tex
	* $Results/tablepanelb.tex
	* $Data/mainsample.dta
	* $Data/mainsample.csv
	
	
	use $Data/GameUserWPdaily_norm.dta, clear
	
	gen month = month(date)

		
	gen zip2 = int( zip/10)
	
	merge m:1 zip2 month using $Data/maxmindirectionsmonth_zip260.dta
	
	keep if _merge ==3
	
	
	gen monthyear = mofd(date)

	gen highpm =  weighted_dailypm > 25 & weighted_dailypm<. 

	gen lowpm = weighted_dailypm > 12 & weighted_dailypm<. 
	
	gen vhighpm = weighted_dailypm > 35 & weighted_dailypm<. 
	
	
	egen cut_winddirection = cut(median_closestwind), at(0(60)360)
	replace cut_winddirection = 0 if median_closestwind ==360

	
	gen maxzipwind = (cut_winddirection ==maxdirection )
	replace maxzipwind = . if maxdirection==.
	
	keep if maxzipwind<. 
	

	
		egen cut_temp = cut(weighted_temperature), at(-40(10)40)

	
reghdfe norm_score weighted_dailypm  weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

eststo all0 


reghdfe norm_score highpm   weighted_wind_speed weighted_precipitation, absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

eststo all1 

 


ivreghdfe norm_score (weighted_dailypm  =maxzipwind )  weighted_wind_speed weighted_precipitation, absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

eststo all2 



ivreghdfe norm_score (highpm =maxzipwind )  weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

eststo all3 




ivreghdfe  score_pctile (weighted_dailypm  =maxzipwind )  weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

eststo pctile1


ivreghdfe  score_pctile (highpm =maxzipwind )  weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

eststo pctile2 




label variable highpm "Daily PM2.5 $>$ 25" 
label variable weighted_dailypm "Daily PM2.5"



	esttab all0 all1 all2 all3 pctile1 pctile2 using $Results/tablepanela.tex, drop(weighted_wind_speed weighted_precipitation) replace se scalars("widstat First stage F") nocon star(* 0.1 ** 0.05 *** 0.001) label nomtitles
	

	
	
	

ivreghdfe norm_score (highpm =maxzipwind )   weighted_wind_speed weighted_precipitation, absorb(anon_id#i.hour monthyear cut_temp i.day_of gamenum ) cluster(anon_id monthyear)

eststo fe3



ivreghdfe norm_score (highpm  =maxzipwind )  weighted_wind_speed weighted_precipitation, absorb(anon_id monthyear cut_temp i.day_of i.zip2#i.month) cluster(anon_id monthyear)

eststo fe4
	
	
	
	
ivreghdfe norm_score (highpm =maxzipwind )  weighted_wind_speed weighted_precipitation if weighted_dailypm < 35, absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

eststo pm1
	
	
	
	

ivreghdfe norm_score (lowpm =maxzipwind )  weighted_wind_speed weighted_precipitation if weighted_dailypm < 35, absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

eststo pm2



	
	

ivreghdfe norm_score (lowpm =maxzipwind )  weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

eststo pm3




ivreghdfe norm_score (vhighpm =maxzipwind )  weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

eststo pm4






label variable lowpm "Daily PM2.5 $>$ 12" 
label variable vhighpm "Daily PM2.5 $>$ 35"





	esttab fe3 fe4 pm1 pm2 pm3 pm4 using $Results/tablepanelb.tex, drop(*weighted_wind_speed *weighted_precipitation) replace se scalars("widstat First stage F") nocon star(* 0.1 ** 0.05 *** 0.001) label nomtitles
	

	
	
*** estimation sample summ stats 

summ highpm if e(sample)
summ lowpm if e(sample)
unique date if highpm ==1 & e(sample)
unique date if lowpm ==1 & e(sample)

unique zip date if e(sample)
unique zip date if highpm ==1 & e(sample)
unique zip date if lowpm ==1 & e(sample)

keep if e(sample)

save $Data/mainsample.dta, replace 

export delimited $Data/mainsample.csv, replace
